#############################################################
#################      Survey Plot (2011-12)    #############
###############      October 10, 2018    ##################
#########  Rerun: December 16, 2022 


rm(list = ls())  
library(foreign)
library(readstata13)
library(ggplot2)  
library(scales)

data=read.dta13("~/Dropbox/Personal Research 2017/replications/IHDS_karn.dta")
table(data$DISTRICT)


#select districts 
kar=data[which(data$DISTRICT=="Shimoga"|data$DISTRICT=="Davanagere"|
                 data$DISTRICT=="Chitradurga"|data$DISTRICT=="Uttar Kannad"|
                 data$DISTRICT=="Haveri"|data$DISTRICT=="Gadag"|
                 data$DISTRICT=="Dharwad"|data$DISTRICT=="Koppal"|
                 data$DISTRICT=="Raichur"|
                 data$DISTRICT=="Gulbarga"|data$DISTRICT=="Bagalkot"|
                 data$DISTRICT=="Bijapur"),]

kar$tr=1
kar$tr[kar$DISTRICT=="Bagalkot"|
         kar$DISTRICT=="Haveri"|kar$DISTRICT=="Bijapur"|
         kar$DISTRICT=="Gadag"|kar$DISTRICT=="Uttar Kannad"|
         kar$DISTRICT=="Dharwad"]=0
table(kar$tr)



table(kar$DISTRICT)


####confidence in politicians
#change categories
table(kar$tr, kar$CI1)
table(kar$CI1)
kar$ci1=1 #confident 
#kar$ci4[kar$CI4=="Only some confidence"|kar$CI4=="Hardly any confidence at all"]=0 #not confident 
kar$ci1[kar$CI1=="Hardly any confidence at all"]=0 #not confident 

table(kar$ci1)

g1=ggplot(kar, aes(x=factor(ci1), group=factor(tr)))+
  geom_bar(aes(y = ..prop.., fill = factor(tr)), stat="count", position=position_dodge())+
  xlab("Confidence in politicians")+ylab("Count")+
  scale_fill_grey(start=0.8, end=0.2, name="Treatment Group",
                      labels=c("Direct Rule", "Indirect Rule"))+
  labs(y = "Percent") +
  geom_text(aes( label = scales::percent(..prop..),
                 y= ..prop.. ), stat= "count", position = position_dodge(0.9), vjust=-0.33) +
  scale_y_continuous(labels=percent)

g1

pdf("surveyplot2011.pdf",width=7,height=5)
g1
dev.off()






